//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Configuration;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Management.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;

namespace EntLibContrib.Query.Configuration.Manageability
{
	/// <summary>
	/// Represents the general configuration information for the Query Application Block.
	/// </summary>
	/// <remarks>
	/// The Query Block does not have any properties of its own.
	/// Instances of <see cref="QueryBlockSetting"/> are still published for the sake of completeness.
	/// </remarks>
	/// <seealso cref="EntLibContrib.Query.Configuration.QuerySettings"/>
	/// <seealso cref="ConfigurationSectionSetting"/>
	[ManagementEntity]
	public class QueryBlockSetting : ConfigurationSectionSetting
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="QueryBlockSetting"/> class.
		/// </summary>
		/// <param name="settings">The query application block configuration.</param>
		public QueryBlockSetting(QuerySettings settings) : base(settings)
		{
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns an enumeration of the published <see cref="QueryBlockSetting"/> instances.
		/// </summary>
		/// <returns></returns>
		[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		[ManagementEnumerator]
		public static IEnumerable<QueryBlockSetting> GetInstances()
		{
			return GetInstances<QueryBlockSetting>();
		}

		/// <summary>
		/// Returns the <see cref="QueryBlockSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <returns>
		/// The published <see cref="QueryBlockSetting"/> instance specified by the values for the key properties,
		/// or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static QueryBlockSetting BindInstance(string applicationName, string sectionName)
		{
			return BindInstance<QueryBlockSetting>(applicationName, sectionName);
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Saves the changes on the <see cref="QueryBlockSetting"/> to its corresponding configuration object.
		/// </summary>
		/// <param name="sourceElement">The configuration object on which the changes must be saved.</param>
		/// <returns>
		/// 	<see langword="true"/> if changes have been saved, <see langword="false"/> otherwise.
		/// </returns>
		/// <remarks>Must be overridden by subclasses to perform the actual save.</remarks>
		protected override bool SaveChanges(ConfigurationElement sourceElement)
		{
			return true; // no changes to save
		}
		#endregion
	}
}
